package org.xtext.runtime.messaging;

import org.xtext.runtime.interpreter.ASTRAClass;
import org.xtext.runtime.interpreter.Agent;

public class LocalMQService implements MessageService {
	public static void launch() {
		new LocalMQService();
	}
	
	public LocalMQService() {
		Agent.defaultMessageService(this);
	}
	
	@Override
	public boolean send(AstraMessage message) {
		for (String name : message.getReceivers()) {
//			System.out.println("sending message to: " + name);
            Agent receiver = ASTRAClass.getInstance(name);
            if ( receiver != null ) {
               receiver.receive(message);
            }
            else {
               System.err.println( "Unknown receiver: " + receiver );
            }
		}
		
		return true;
	}
}
